﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using QLNet;
using FinPlusAssembler;
using p = FinPlusCompQuant.QLConvParser;

namespace FinPlusCompQuant
{
    public class CreditDefaultSwapTrade : Trade
    {
        //construct
        public CreditDefaultSwapTrade(string marketName, string cacheName, string id, string curveName, double quotedSpread, string protSellBuy, double nominal, DateTime start, DateTime maturity, string premFreq, string premConv, string payConv, string dayCount, string holidays)
        {
            Id = id;

            var market = Markets.Instance.GetMarket(marketName);
            var cache = Caches.Instance.GetCache(cacheName);
            var type = p.BuyerSeller(protSellBuy).EnumParse<Protection.Side>();

		    var schedule = new  MakeSchedule().from(start)
                .to(maturity)
                .withFrequency(p.Freq(premFreq))
                .withCalendar(p.Calendar(holidays))
                .withTerminationDateConvention(p.BizConv(premConv))
                .withRule(DateGeneration.Rule.TwentiethIMM).value();

            Underlying = new CreditDefaultSwap(type, nominal, quotedSpread, schedule, p.BizConv(payConv), p.DayCount(dayCount));

            cache.Add(id, this, curveName);
        }
    }
}
